<form method="post" id="form_vacabulary_edit" style="display:none;">
  <table class="itable">
    <tr>
      <td width="80px"></td>
      <td id="msg"></td>
    </tr>
    <tr>
      <td width="80px">id</td>
      <td><input type="text" value="0" name="vid" readonly="false"/></td>
    </tr>
    <tr>
      <td>名称</td>
      <td><input type="text" value="" name="name"/></td>
    </tr>
    <tr>
      <td>机读名称</td>
      <td><input type="text" value="" name="machine_name"/></td>
    </tr>
    <tr>
      <td>描述</td>
      <td><textarea name="description"></textarea></td>
    </tr>
    <tr>
      <td>排序</td>
      <td><input type="text" value="0" name="weight"/></td>
    </tr>
  </table>
</form>

<table id="vocabulary_list" class="itable">
  <thead>
    <tr>
      <th>ID</th>
      <th>名称</th>
      <th>机读名称</th>
      <th>操作分类 </th>
      <th>操作术语表 </th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td colspan="9" class="dataTables_empty">Loading...</td>
    </tr>
  </tbody>
</table>
<script type="text/javascript">
var vTable = $("#vocabulary_list").dataTable({
  "bServerSide": true,
  "sAjaxSource": "admin.php?ctrl=taxonomy&act=vocabulary_list_data",
  "oLanguage": {
    "sUrl": "style/js/dt_cn.txt"
  }
});

function del_voc(vid){
	if(confirm('确定删除分类?')){
		$.ajax({
      type: "POST",
      url: "admin.php?ctrl=taxonomy&act=vocabulary_delete",
      data: "vid="+vid,
      timeout: 20000,
      error: function(){alert('error');},
      success: function(result){
        if(result == '1'){
        	$('#taxonomy_tabs').tabs( "load" , 0 );
        }else if(result == '-1'){
          alert('删除失败');
        }else if(result == '-2'){
          alert('分类下有数据，不能删除');
        }else if(result == '-3'){
          alert('参数错误');
        }else{
        	alert('未知错误'+result);
        }
      }
    });
	}
}

function edit_voc(vid){
	$.ajax({
     type: "POST",
     url: "admin.php?ctrl=taxonomy&act=vocabulary_get",
     data: "vid="+vid,
     timeout: 20000,
     error: function(){alert('error');},
     success: function(result){
    	 result = JSON.parse(result);
       if(result == '-1'){
         alert('读取分类失败');
         return false;
       }else{
    	   fillForm('input', 'vid', result.vid);
    	   fillForm('input', 'name', result.name);
    	   fillForm('input', 'machine_name', result.machine_name);
    	   $("#form_vacabulary_edit textarea[name='description']").html(result.description);
    	   fillForm('input', 'weight', result.weight);
       }
     }
   });
	
	$( "#form_vacabulary_edit" ).attr('title', '编辑分类').die().dialog({
     modal: true,
     buttons: {
       '保存': function() {
    	   $.ajax({
  		      type: "POST",
  		      url: "admin.php?ctrl=taxonomy&act=vocabulary_update",
  		      data: $(this).serialize(),
  		      timeout: 20000,
  		      error: function(){alert('error');},
  		      success: function(result){
  		        if(result == 'success'){
  		          $('#taxonomy_tabs').tabs( "load" , 0 );
  		        }else{
  		        	alert(result);
  		        }
  		      }
  		    });
    	   
    	   $( this ).dialog( "close" );
       }
     }
   });
}

function fillForm(type, name, value){
	$("#form_vacabulary_edit "+type+"[name='"+name+"']").attr('value', value);
}

function term_list(vid){
	$taxonomy_tabs.tabs( "url" , 2 , 'admin.php?ctrl=taxonomy&act=term_list&vid='+vid );
	$taxonomy_tabs.tabs( "select" , 2 );
	
}

function term_add(vid){
	$taxonomy_tabs.tabs( "url" , 3 , 'admin.php?ctrl=taxonomy&act=term_add&vid='+vid );
	$taxonomy_tabs.tabs( "select" , 3 );
	
}
</script>